import json
import os

from framework.httpRequest import HttpRequest
from utils.readFile import ReadFile


class GetToken:
	@staticmethod
	def getToken():
		httpRequest = HttpRequest()
		fileInfo = (ReadFile.readEnvConfigYaml((os.path.dirname(os.path.dirname(os.path.abspath(__file__))) + "\\config\\config.yml")))
		httpRequest.host = fileInfo['environment']
		username = fileInfo['username']
		password = fileInfo['password']
		httpRequest.path = '/wx/auth/login'
		httpRequest.method = 'post'
		httpRequest.type = 'json'
		httpRequest.bodyData = {"username": username, "password": password}
		response = httpRequest.send()
		token = json.loads(response.text)['data']['token']
		return token